/**
 * 
 */
package org.jeecg.client;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author bright
 * 业务数据行
 */
public class DataRow{
	static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
	private Map<String, String> fields;
	
//	private DataTable table;
	public DataRow(DataTable table) {
		super();
		this.fields = new HashMap<String, String>();
//		this.table = table;
	}
	
	public static SimpleDateFormat getSdf() {
		return sdf;
	}
	
	public static void setSdf(SimpleDateFormat sdf) {
		DataRow.sdf = sdf;
	}
	
	/**
	 * 设置字段值
	 * @param name
	 * @param value
	 */
	public void set(String name, String value){
		name = name.toLowerCase();
		fields.put(name, value);
	}
	
	/**
	 * 获取字符串类型的字段值
	 * @param name
	 * @return
	 */
	public String getString(String name){
		name = name.toLowerCase();
		return fields.get(name);
	}

	/**
	 * 获取Int类型的字段值
	 * @param name
	 * @return
	 */
	public int getInt(String name){
		name = name.toLowerCase();
		return Integer.parseInt(fields.get(name));
	}

	/**
	 * 获取double类型的字段值
	 * @param name
	 * @return
	 */
	public double getDouble(String name){
		name = name.toLowerCase();
		return Double.parseDouble(fields.get(name));
	}

	/**
	 * 获取日期时间类型的字段值
	 * @param name
	 * @return
	 * @throws ParseException
	 */
	public Date getDate(String name) throws ParseException{
		name = name.toLowerCase();
		String str = fields.get(name);
//		int pos = str.lastIndexOf(':');
//		str = str.substring(0, pos) + str.substring(pos + 1);
		synchronized (sdf){
			return sdf.parse(str);
		}
	}

//	public DataTable getTable() {
//		return table;
//	}
//
//	public void setTable(DataTable table) {
//		this.table = table;
//	}

	public Map<String, String> getFields() {
		return fields;
	}

	public void setFields(Map<String, String> fields) {
		this.fields = fields;
	}
}
